package elsim.common

import com.google.common.annotations.VisibleForTesting;

class Clock {
  private static final Clock instance = new Clock(0);

  private int clockValue
  private final Set<Tickable> controlledComponents = new HashSet()

  @VisibleForTesting
  Clock(int clock) {
    this.clockValue = clock
  }

  public static final Clock getClock() {
    return instance
  }

  public void tick() {
    clockValue++

    for (Tickable t: controlledComponents) {
      t.tick(clockValue)
    }
  }

  public int getClockValue() {
    return clockValue
  }
  
  public void resetClock(int value) {
    clockValue = value;
  }

  void registerObject(Tickable object) {
    controlledComponents.add(object)
  }
}
